
package com.joysuch.wwyt.core.repository;

import com.joysuch.wwyt.core.entity.BaseImageRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * BaseImageRepository
 */
public interface BaseImageRespositoryDao extends JpaRepository<BaseImageRepository, Long> {
    public Page<BaseImageRepository> findAll(Specification<BaseImageRepository> spec, Pageable pageable);

    public BaseImageRepository save(BaseImageRepository bean);

    @Query(value = "SELECT * FROM wwyt_base_image_repository wi INNER JOIN wwyt_base_image_type_repository wt ON wt.image_id = wi.ID AND wt.image_id = ?1 and wt.type_code = 'user_cap' and wt.delete_flag = '0' and wi.DELETE_FLAG = '0' ", nativeQuery = true)
    BaseImageRepository findImageByCapId(Long capId);

    public void delete(BaseImageRepository bean);

    public BaseImageRepository findFirstByFingerPrint(String fingerPrint);

    @Query(value = "select unique_id from wwyt_base_image_repository where id =?1 and locate_sync = 1 and delete_flag = '0' ", nativeQuery = true)
    Long getUniqueIdById(Long capId);

    @Query(value = " SELECT r.unique_id FROM wwyt_base_image_repository r INNER JOIN wwyt_base_image_type_repository t ON r.id = t.image_id WHERE t.delete_flag ='0' AND r.delete_flag = '0' AND r.locate_sync = 1 AND  t.id =?1", nativeQuery = true)
    Long getUniqueIdByTypeId(Long id);

    @Query(value = "select id from wwyt_base_image_repository where unique_id =?1  and delete_flag = '0' ", nativeQuery = true)
    Long findByUniqueId(String iconUniqueId);

    @Query(value = "select * from wwyt_base_image_repository where unique_id in ?1  and delete_flag = '0' ", nativeQuery = true)
    List<BaseImageRepository> findByUniqueIds(List<String> iconUniqueIds);


    @Query(value = "select * from wwyt_base_image_repository where id in ?1  and delete_flag = '0' ", nativeQuery = true)
    List<BaseImageRepository> findByIds(List<Long> ids);
}
